package org.devocean.groupbuying.domain;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

@SuppressWarnings("serial")
@Entity
public class PurchaseItem implements Serializable {

	@Id
	@GeneratedValue
	private Integer purchaseItemID;
	private double unitPrice;
	private double amount;
	private double tax;
	private Integer quantity;
	private Date statusDate;
	private String status;

	@ManyToOne(cascade = CascadeType.ALL,fetch = FetchType.LAZY)
	@JoinColumn(name = "purchaseID", referencedColumnName = "purchaseID", nullable = false)
	private Purchase purchase;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "discountID", referencedColumnName = "discountID", nullable = false)
	private Discount discount;

	@OneToMany(mappedBy="item")
	private Set<SerialKey> serialKeys = new HashSet<SerialKey>();

	public PurchaseItem() {
	}

	public Integer getPurchaseItemID() {
		return purchaseItemID;
	}

	public void setPurchaseItemID(Integer purchaseItemID) {
		this.purchaseItemID = purchaseItemID;
	}

	public double getAmount() {
		return amount;
	}

	public void setAmount(double amount) {
		this.amount = amount;
	}

	public Integer getQuantity() {
		return quantity;
	}

	public void setQuantity(Integer quantity) {
		this.quantity = quantity;
	}

	public Date getStatusDate() {
		return statusDate;
	}

	public void setStatusDate(Date statusDate) {
		this.statusDate = statusDate;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public double getTax() {
		return tax;
	}

	public void setTax(double tax) {
		this.tax = tax;
	}

	public double getUnitPrice() {
		return unitPrice;
	}

	public void setUnitPrice(double unitPrice) {
		this.unitPrice = unitPrice;
	}

	public Purchase getPurchase() {
		return purchase;
	}

	public void setPurchase(Purchase purchase) {
		this.purchase = purchase;
	}

	public Discount getDiscount() {
		return discount;
	}

	public void setDiscount(Discount discount) {
		this.discount = discount;
	}

	public Set<SerialKey> getSerialKeys() {
		return serialKeys;
	}

	public void setSerialKeys(Set<SerialKey> serialKeys) {
		this.serialKeys = serialKeys;
	}

	@Override
	public String toString() {
		return "PurchaseItem [purchaseItemID=" + purchaseItemID
				+ ", unitPrice=" + unitPrice + ", amount=" + amount + ", tax="
				+ tax + ", quantity=" + quantity + ", statusDate=" + statusDate
				+ ", status=" + status;
	}

}
